# eric7.QScintilla.SpellChecker

Module implementing the spell checker for the editor component.

The spell checker is based on pyenchant.

### Global Attributes

None

### Classes

SpellChecker | Class implementing a pyenchant based spell checker.

### Functions

None

## SpellChecker

Class implementing a pyenchant based spell checker.

### Derived from

QObject

### Class Attributes

_spelling_dict
_spelling_lang

### Class Methods

_getDict | Protected class method to get a new dictionary.
getAvailableLanguages | Class method to get all available languages.
getDefaultPath | Class method to get the default path names of the user dictionaries.
getUserDictionaryPath | Class method to get the path name of a user dictionary file.
isAvailable | Class method to check, if spellchecking is available.
setDefaultLanguage | Class method to set the default language.

### Methods

SpellChecker | Constructor
__checkDocumentPart | Private method to check some part of the document.
__getNextWord | Private method to get the next word in the text after the given position.
__incrementalCheck | Private method to check the document incrementally.
__iter__ | Special method to create an iterator.
__next__ | Special method to advance to the next error.
add | Public method to add a word to the personal word list.
checkCurrentPage | Public method to check the currently visible page.
checkDocument | Public method to check the complete document.
checkDocumentIncrementally | Public method to check the document incrementally.
checkLines | Public method to check some lines of text.
checkSelection | Public method to check the current selection.
checkWord | Public method to check the word at position pos.
clearAll | Public method to clear all spelling markers.
getContext | Public method to get the context of a faulty word.
getError | Public method to get information about the last error found.
getLanguage | Public method to get the current language.
getSuggestions | Public method to get suggestions for the given word.
ignoreAlways | Public method to tell the checker, to always ignore the given word or the current word.
initCheck | Public method to initialize a spell check.
remove | Public method to add a word to the personal exclude list.
replace | Public method to tell the checker to replace the current word with the replacement string.
replaceAlways | Public method to tell the checker to always replace the current word with the replacement string.
setLanguage | Public method to set the current language.
setMinimumWordSize | Public method to set the minimum word size.
stopIncrementalCheck | Public method to stop an incremental check.

### Static Methods

None

#### SpellChecker._getDict (class method)

_getDict(lang, pwl="", pel="")

Protected class method to get a new dictionary.

lang (str)
  the language to be used as the default. The string should be in language locale format (e.g. en_US, de).
pwl (str)
  name of the personal/project word list
pel (str)
  name of the personal/project exclude list

Return:
  reference to the dictionary

Return Type:
  enchant.Dict

#### SpellChecker.getAvailableLanguages (class method)

getAvailableLanguages()

Class method to get all available languages.

Return:
  list of available languages

Return Type:
  list of str

#### SpellChecker.getDefaultPath (class method)

getDefaultPath(isException=False)

Class method to get the default path names of the user dictionaries.

isException (bool)
  flag indicating to return the name of the default exception dictionary

Return:
  file name of the default user dictionary or the default user exception dictionary

Return Type:
  str

#### SpellChecker.getUserDictionaryPath (class method)

getUserDictionaryPath(isException=False)

Class method to get the path name of a user dictionary file.

isException (bool)
  flag indicating to return the name of the user exception dictionary

Return:
  file name of the user dictionary or the user exception dictionary

Return Type:
  str

#### SpellChecker.isAvailable (class method)

isAvailable()

Class method to check, if spellchecking is available.

Return:
  flag indicating availability

Return Type:
  bool

#### SpellChecker.setDefaultLanguage (class method)

setDefaultLanguage(language)

Class method to set the default language.

language (str)
  the language to be used as the default. The string should be in language locale format (e.g. en_US, de).

#### SpellChecker (Constructor)

SpellChecker(editor, indicator, defaultLanguage=None, checkRegion=None)

Constructor

editor (QScintilla.Editor)
  reference to the editor object
indicator (int)
  spell checking indicator
defaultLanguage (str)
  the language to be used as the default. The string should be in language locale format (e.g. en_US, de).
checkRegion (function)
  reference to a function to check for a valid region

#### SpellChecker.__checkDocumentPart

__checkDocumentPart(startPos, endPos)

Private method to check some part of the document.

startPos (int)
  position to start at
endPos (int)
  position to end at

#### SpellChecker.__getNextWord

__getNextWord(pos, endPosition)

Private method to get the next word in the text after the given position.

pos (int)
  position to start word extraction
endPosition (int)
  position to stop word extraction

Return:
  tuple of three values (the extracted word, start position, end position)

Return Type:
  tuple of (str, int, int)

#### SpellChecker.__incrementalCheck

__incrementalCheck()

Private method to check the document incrementally.

#### SpellChecker.__iter__

__iter__()

Special method to create an iterator.

Return:
  self

Return Type:
  SpellChecker

#### SpellChecker.__next__

__next__()

Special method to advance to the next error.

Return:
  self

Return Type:
  SpellChecker

Raises StopIteration:
  raised to indicate the end of the iteration

#### SpellChecker.add

add(word=None)

Public method to add a word to the personal word list.

word (str)
  word to add

#### SpellChecker.checkCurrentPage

checkCurrentPage()

Public method to check the currently visible page.

#### SpellChecker.checkDocument

checkDocument()

Public method to check the complete document.

#### SpellChecker.checkDocumentIncrementally

checkDocumentIncrementally()

Public method to check the document incrementally.

#### SpellChecker.checkLines

checkLines(firstLine, lastLine)

Public method to check some lines of text.

firstLine (int)
  line number of first line to check
lastLine (int)
  line number of last line to check

#### SpellChecker.checkSelection

checkSelection()

Public method to check the current selection.

#### SpellChecker.checkWord

checkWord(pos, atEnd=False)

Public method to check the word at position pos.

pos (int)
  position to check at
atEnd (bool)
  flag indicating the position is at the end of the word to check

#### SpellChecker.clearAll

clearAll()

Public method to clear all spelling markers.

#### SpellChecker.getContext

getContext(wordStart, wordEnd)

Public method to get the context of a faulty word.

wordStart (int)
  the starting position of the word
wordEnd (int)
  the ending position of the word

Return:
  tuple of the leading and trailing context

Return Type:
  tuple of (str, str)

#### SpellChecker.getError

getError()

Public method to get information about the last error found.

Return:
  tuple of last faulty word, starting position of the faulty word and ending position of the faulty word

Return Type:
  tuple of (str, int, int)

#### SpellChecker.getLanguage

getLanguage()

Public method to get the current language.

Return:
  current language in language locale format

Return Type:
  str

#### SpellChecker.getSuggestions

getSuggestions(word)

Public method to get suggestions for the given word.

word (str)
  word to get suggestions for

Return:
  list of suggestions

Return Type:
  list of str

#### SpellChecker.ignoreAlways

ignoreAlways(word=None)

Public method to tell the checker, to always ignore the given word or the current word.

word (str)
  word to be ignored

#### SpellChecker.initCheck

initCheck(startPos, endPos)

Public method to initialize a spell check.

startPos (int)
  position to start at
endPos (int)
  position to end at

Return:
  flag indicating successful initialization

Return Type:
  bool

#### SpellChecker.remove

remove(word)

Public method to add a word to the personal exclude list.

word (str)
  word to add

#### SpellChecker.replace

replace(replacement)

Public method to tell the checker to replace the current word with the replacement string.

replacement (str)
  replacement string

#### SpellChecker.replaceAlways

replaceAlways(replacement)

Public method to tell the checker to always replace the current word with the replacement string.

replacement (str)
  replacement string

#### SpellChecker.setLanguage

setLanguage(language, pwl="", pel="")

Public method to set the current language.

language (str)
  the language to be used as the default. The string should be in language locale format (e.g. en_US, de).
pwl (str)
  name of the personal/project word list
pel (str)
  name of the personal/project exclude list

#### SpellChecker.setMinimumWordSize

setMinimumWordSize(size)

Public method to set the minimum word size.

size (int)
  minimum word size

#### SpellChecker.stopIncrementalCheck

stopIncrementalCheck()

Public method to stop an incremental check.

Up